 #!/bin/env ruby
# encoding: utf-8

###
#  submit empty input is ignored
#  submit string with length more than 255 symbols:  “Title should contain no more than 255 symbols”
#  submit benefit with title, which is already exist: “Benefit with such title is already exist”
###


###submit empty input is ignored 
#input param text_field , save button or add new button  ?? do nothing...
# A - table with benefits
def empty_benefit_table(fieldT, buttonC)
  find_empty = false
  if (fieldT.text !=nil) then
  	bText=fieldT.text
  end
  fieldT.clear
  buttonC.click
  (fieldT.text == bText).should be_truthy
  # look for empty benefit       
  # A =  table(class: "table table-hover js-admin-table-for-department table-striped")
  # A.tbody.trs.each do |row|
  #   row.cells.each do |cell| 
  #     if (cell.text == nil || cell.text == "") then
  #       STDERR.puts "nil"
  #       find_empty = true
  #       break
  #     end
  #   end
  # end     
  # (find_empty == false).should be_truthy  
end

def empty_benefit_add(fieldT, buttonC)
  find_empty = false
  if (fieldT.text !=nil) then
  	bText=fieldT.text
  end
  fieldT.clear
  buttonC.click
  (fieldT.text == bText).should be_truthy
  # look for empty benefit       
  tableA =  table(class: "table table-hover js-admin-table-for-department table-striped")
  tableA.tbody.trs.each do |row|
    row.cells.each do |cell| 
      if (cell.text == nil || cell.text == "") then
        STDERR.puts cell.text + "nil"
        find_empty = true
        break
      end
    end
  end     
  (find_empty).should be_falsy  
end


 # -- submit string with length more than 255 symbols:  “Title should contain no more than 255 symbols”  
  def huge_benefit(fieldT, buttonC)
      ustr='a'
      256.times{|i| ustr+='a'}
      ustr=ustr+'a'
      fieldT.clear
      fieldT.set ustr
      buttonC.click      
      span(class: "help-block", text: "Title should contain no more than 255 symbols").wait_until_present(5)      
  end